<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    <div class="container-div">
		<div class="btn-group hidden-xs" id="toolbar" role="group">
			<a class="btn btn-outline btn-success btn-rounded" onclick="createCache()" shiro:hasPermission="module:ossFileCache:add">
				<i class="fa fa-plus"></i> 生成缓存
			</a>
			<a class="btn btn-outline btn-danger btn-rounded" onclick="clearCache()" shiro:hasPermission="module:ossFileCache:remove">
				<i class="fa fa-trash-o"></i> 清空缓存
			</a>
		</div>
			
		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table" data-mobile-responsive="true" style="white-space:nowrap"></table>
		</div>
    </div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('module:ossFileCache:edit')}]];
        var removeFlag = [[${@permission.hasPermi('module:ossFileCache:remove')}]];
        var prefix = ctx + "module/ossFileCache"

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "OSS 缓存",
                columns: [{
		            checkbox: true
		        },
				{
					field : 'ossFileCacheId', 
					title : '主键' 
				},
				{
					field : 'url', 
					title : '访问链接',
					formatter: function (value, row, index) {
						var actions = [];
						actions.push('<a class="' +  '" href="'+value+'" target="_blank" >'+value+'</a>');

						return actions.join('');
					}
				},
				{
					field : 'fileSize', 
					title : '文件大小',
					sortable: true
				},
				{
					field : 'fileName', 
					title : '文件名称' 
				},
				{
					field : 'bucketName', 
					title : '存储空间名称' 
				},
                {
                    field : 'lastModified',
                    title : '修改时间',
					sortable: true
                }
                ]
            };
            $.table.init(options);
        });

		function clearCache() {
			url=  "/module/ossFileCache/clearCache"

			$.modal.confirm("确定要清空缓存吗?", function() {
				layer.msg('执行成功,正在清除缓存,请稍后…', { icon: 1 });
				var config = {
					url:  url,
					type: "post",
					success: function(result) {
						if (result.code == web_status.SUCCESS) {
							$.modal.alertSuccess(result.msg);
						} else {
							$.modal.alertError(result.msg);
						}
					}
				};
				$.ajax(config);
			})
		}

		function createCache() {
			url=  "/module/ossFileCache/createCache"

			$.modal.confirm("确定要生成缓存吗?", function() {
				layer.msg('执行成功,正在生成缓存,请稍后…', { icon: 1 });
				var config = {
					url:  url,
					type: "post",
					success: function(result) {
						if (result.code == web_status.SUCCESS) {
							$.modal.alertSuccess(result.msg);
						} else {
							$.modal.alertError(result.msg);
						}
					}
				};
				$.ajax(config);
			})
        }
    </script>
</body>
</html>